package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println();
        System.out.println("*************************");

        Scanner scanner=new Scanner(System.in);

        System.out.println("请输入你要归还的书名：");
        String input=scanner.nextLine();
        int bnum=bookList.getNum();

        for (int i = 0; i < bnum; i++) {
            Book book=bookList.getBooks(i);

            if (!book.isBorrow()){
                System.out.println("这本书未被借出，无法归还");
                System.out.println();
                System.out.println("*************************");
                return;
            }

            if (input.equals(book.getName())){
                book.setBorrow(false);
                System.out.println("归还成功！");
                System.out.println();
                System.out.println("*************************");
                return;
            }

        }
        System.out.println("未找到该书籍，无法归还！");
        System.out.println();
        System.out.println("*************************");

    }
}
